package org.jeecg.modules.wuda.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wuda.entity.WudaIrrigation;
import org.jeecg.modules.wuda.service.IWudaIrrigationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 灌溉    表
 * @Author: jeecg-boot
 * @Date: 2022-02-27
 * @Version: V1.0
 */
@Api(tags = "灌溉	表")
@RestController
@RequestMapping("/app/wuda/wudaIrrigation")
@Slf4j
public class AppWudaIrrigationController extends JeecgController<WudaIrrigation, IWudaIrrigationService> {
    @Autowired
    private IWudaIrrigationService wudaIrrigationService;
    /**
     * 添加用来控制app端是否能访问
     *

     * @return
     */
    @RequiresPermissions({"wudaIrrigation"})
    @PostMapping(value = "/toAdd")
    public Result toAdd() {
        return Result.OK("true");
    }

    /**
     * 分页列表查询
     *

     * @return
     */
    @RequiresPermissions({"wudaIrrigation"})

    //@AutoLog(value = "灌溉	表-分页列表查询")
    @ApiOperation(value = "灌溉	表-分页列表查询", notes = "灌溉	表-分页列表查询")
    @GetMapping(value = "/list")
    public Result queryPageList() {
        List<WudaIrrigation> list = wudaIrrigationService.list();
        return Result.OK(list);
    }

    /**
     * 添加
     *
     * @param wudaIrrigation
     * @return
     */
    @AutoLog(value = "灌溉	表-添加")
    @ApiOperation(value = "灌溉	表-添加", notes = "灌溉	表-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody WudaIrrigation wudaIrrigation) {
        wudaIrrigationService.save(wudaIrrigation);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param wudaIrrigation
     * @return
     */
    @AutoLog(value = "灌溉	表-编辑")
    @ApiOperation(value = "灌溉	表-编辑", notes = "灌溉	表-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody WudaIrrigation wudaIrrigation) {
        wudaIrrigationService.updateById(wudaIrrigation);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "灌溉	表-通过id删除")
    @ApiOperation(value = "灌溉	表-通过id删除", notes = "灌溉	表-通过id删除")
    @PostMapping(value = "/delete/{id}")
    public Result<String> delete(@PathVariable String id) {
        wudaIrrigationService.removeById(id);
        return Result.OK("删除成功!");
    }



    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "灌溉	表-通过id查询")
    @ApiOperation(value = "灌溉	表-通过id查询", notes = "灌溉	表-通过id查询")
    @GetMapping(value = "/queryById/{id}")
    public Result<WudaIrrigation> queryById(@PathVariable String id) {
        WudaIrrigation wudaIrrigation = wudaIrrigationService.getById(id);
        if (wudaIrrigation == null) {
            return Result.error("未找到对应数据", null);
        }
        return Result.OK(wudaIrrigation);
    }



}
